﻿#region << 文件说明 >>

/*----------------------------------------------------------------
 * 命名空间：Vampirewal.BlogCore.Controls
 * 唯一标识：6c49a32d-6914-47e0-9495-26cb20ff9a58
 * 文件名：TipContainer
 *
 * 创建者：杨程
 * 电子邮箱：235160615@qq.com
 * 创建时间：2024/6/17 14:00:31
 * 版本：V1.0.0
 * 描述：
 *
 * ----------------------------------------------------------------
 * 修改人：
 * 时间：
 * 修改说明：
 *
 * 版本：V1.0.1
 *----------------------------------------------------------------*/

#endregion << 文件说明 >>

namespace Vampirewal.BlogCore;

/// <summary>
/// TIP容器
/// </summary>
public sealed class Tip : ContainerControlBase
{
    /// <summary>
    /// 构造函数
    /// </summary>
    internal Tip()
    {
    }

    public override string Title { get; set; }
    public override List<ControlBase> Children { get; internal set; }
    public override string Id { get; set; }

    public TipType Type { get; set; }

    public override string ConverToHtml()
    {
        StringBuilder sb = new StringBuilder();

        string backgroundColor = "#409eff1a";
        string borderleftColor = "#409eff";
        string icon = "<Sunny color=\"#409eff\" size=\"50\"/>";

        switch (Type)
        {
            case TipType.Tip:
                //backgroundColor = "#409eff1a";
                //borderleftColor = "#409eff";
                //icon = "<Sunny />";
                break;

            case TipType.Warning:
                //sb.AppendLine($"<div style=\"padding:8px 16px;background-color:#f56c6c1a;border-radius:4px;border-left:5px solid #f56c6c;margin:20px 0;\">");
                //sb.AppendLine($"<p style=\"font-weight:700;\"><el-icon><WarnTriangleFilled /></el-icon>{Title}</p>");
                backgroundColor = "#f56c6c1a";
                borderleftColor = "#f56c6c";
                icon = "<WarnTriangleFilled color=\"#f56c6c\" size=\"50\"/>";
                break;

            case TipType.Success:
                //sb.AppendLine($"<div style=\"padding:8px 16px;background-color:#e6f6e6;border-radius:4px;border-left:5px solid #009400;margin:20px 0;\">");
                //sb.AppendLine($"<p style=\"font-weight:700;\"><el-icon><WarnTriangleFilled /></el-icon>{Title}</p>");
                backgroundColor = "#e6f6e6";
                borderleftColor = "#009400";
                icon = "<Flag color=\"#009400\" size=\"50\"/>";
                break;

            default:
                break;
        }

        sb.AppendLine($"<div style=\"padding:8px 16px;background-color:{backgroundColor};border-radius:4px;border-left:5px solid {borderleftColor};margin:20px 0;\">");
        sb.AppendLine($"<p style=\"font-weight:700;\"><el-icon>{icon}</el-icon>{Title}</p>");

        //sb.AppendLine($"{Title}");
        foreach (var item in Children)
        {
            sb.AppendLine($"{item.ConverToHtml()}");
        }
        sb.AppendLine($"</div>");

        return sb.ToString();
    }
}

public enum TipType
{
    Tip,
    Warning,
    Success
}

public static partial class App
{
    /// <summary>
    /// 新增Tip容器
    /// </summary>
    /// <param name="title"></param>
    /// <param name="type"></param>
    /// <param name="children"></param>
    /// <returns></returns>
    public static Tip CreateTip(string title, TipType type, Action<List<ControlBase>> children)
    {
        Tip tip = new Tip()
        {
            Id = GenerateId(),
            Title = title,
            Type = type,
        };

        tip.Children = new List<ControlBase>();

        children?.Invoke(tip.Children);

        return tip;
    }
}